<!DOCTYPE html>
<html>
  
  <head>
    <meta charset="UTF-8">
    <title>后台管理</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi" />
    <link rel="shortcut icon" href="/favicon.ico" type="image/x-icon" />
    <link rel="stylesheet" href="../../css/font.css">
    <link rel="stylesheet" href="../../css/xadmin.css">
    <script type="text/javascript" src="../../js/jquery-3.2.1.js"></script>
    <script type="text/javascript" src="../../lib/layui/layui.js" charset="utf-8"></script>
    <script type="text/javascript" src="../../js/xadmin.js"></script>
  </head>
  
  <body>
    <div class="x-body">
	   <table class="layui-hide" id="test" lay-filter="test"></table>
    </div>
    <script type="text/html" id="barDemo">
	  	<a class="layui-btn layui-btn-primary layui-btn-xs" lay-event="accept">接受</a>
			<a class="layui-btn layui-btn-xs" lay-event="edit">安排</a>
		</script>
    
    <script type="text/javascript">
			layui.use(['table', 'layer'], function() {
					var layer = layui.layer;
					var table = layui.table;
					
					var data = {enable:1};
	        if(window.location.href.indexOf("?")!=-1){
	        	 var para =  window.location.href.substr(window.location.href.indexOf("?")+1);
	        	 if(para != null && para != undefined && para.trim() != ''){
	                 para = para.replace(/=/g,"':'");
	                 para = para.replace(/&/g,"','");
	                 data = $.extend({},data,eval("({'"+para+"'})"));
	                // data = JSON.parse('{'+para+'}');
	                 console.log(data);
	                 console.log(para);
	             }
	        }
        
					table.render({
					    elem: '#test'
					    ,id: 'fixTable'
					    ,height: 605
					    ,url: '../findFixTable' //数据接口
					    ,where:data
					    ,page: {limits:[10, 20, 30]} //开启分页
					    ,toolbar: true  //开启工具栏
					    ,request: {
					   		pageName: 'pageNo' //页码的参数名称，默认：page
					    	,limitName: 'pageSize' //每页数据量的参数名，默认：limit
					  	}
					    ,cols: [[ //表头
					     
					      {field: 'fixBillId', title: 'ID', width:80, sort: true, fixed: 'left'}
					      ,{field: 'userId', title: '用户ID', width:80, sort: true, fixed: 'left'}
					      ,{field: 'presonName', title: '用户', width:100,  fixed: 'left'}
					      ,{field: 'breakObject', title: '需要维修的物件', width:150}
					      ,{field: 'breakCause', title: '问题描述', width: 250}
					      ,{field: 'fixBillSendTime', title: '申请时间', width:120, sort: true
					    	   ,templet:function(d){
					    		   return toMyDateString(d.fixBillSendTime);
					    	   }	    
					      }
					      ,{field: 'workerName', title: '维修师傅',sort: true, width: 100 }
					      ,{field: 'workerTelephone', title: '联系方式', width:150}
					      ,{field: 'applyTime', title: '预约时间', sort: true, width:120
					    	  ,templet:function(d){
	                                 if(d.applyTime!=null&&d.applyTime.toString().trim()!=""){
	                                      return toMyDateString(d.applyTime);
	                                 }
	                                 return "";
					    	  }
                           }
					      ,{field: 'processing', title: '过程描述', width:250}
					      ,{fixed: 'right', title: '状态', width: 105
					      		,templet:function(d){
					      			if(d.enable==2){
					      				return "已撤销";
					      			}
					      			if(d.isCheck){
	                                     var status="处理中";
	                                        if(d.isApply){
	                                            status="已安排师傅";
	                                            if(d.isFinish){
	                                                status="已完成";
	                                            }
	                                        }
	                                        return status;
					      			}else{
					      				return "待处理";
					      			}
					      		}
					      	}
					      ,{fixed: 'right', title: '操作', width: 120,templet:'#barDemo'}
					    ]]
					 
				   });
				     //监听行工具事件
				  table.on('tool(test)', function(obj){
				    var data = obj.data;
				    if(obj.event === 'accept'){
				    	if(data.enable!=1){
				    		layer.alert('不可接收' ,{icon: 0});
				    	}else{
				    		if(data.isCheck!=0){
	                            layer.alert('已接收' ,{icon: 0});
	                        }else{
	                            var fix = {};
	                            fix.fixBillId = data.fixBillId;
	                            fix.checkBillTime = new Date();
	                            fix.isCheck = 1;
	                            $.ajax({
	                              type: "post",
	                              url: "../updateFix",
	                              async: true,
	                              data: fix,
	                              success: function(result) {
	                                location.reload();
	                              },
	                              error:function() {layer.alert("与服务器连接异常", {icon: 2});}
	                            }); 
	                        }
				    	}
				    } else if(obj.event === 'edit'){
				    	x_admin_show('编辑','./fix-update.html?fixBillId='+data.fixBillId);
				    }
 				  });
			});
			
			function toMyDateString(timeMillis){
                var time = new Date(timeMillis);
                var month = time.getMonth()+1;
                if(month<10) month='0'+month;
                var day = time.getDate();
                if(day<10) day='0'+day;
                return time.getFullYear()+"-"+month+"-"+day;;
            }
			
		
		</script>

  </body>

</html>